This patch is to make xentop able to print vcpu usage for out of order
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sat, 22 Oct 2005 06:37:15 +0000 (07:37 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sat, 22 Oct 2005 06:37:15 +0000 (07:37 +0100)
enabled vcpus in a domain. This really isn't an issue anymore with the
changes made to dom0 ops and xm/xend.

But, I provide it because:

- Josh noticed my previous patch called getvcpuinfo twice for each vpcu,
which was completely silly.

- this patch would be useful in the remote chance that domain vpcus are
enabled out of order.

Signed-off-by: Daniel Stekloff <dsteklof@us.ibm.com>
tools/xenstat/libxenstat/src/xen-interface.c
tools/xenstat/libxenstat/src/xen-interface.h
tools/xenstat/libxenstat/src/xenstat.c
tools/xenstat/libxenstat/src/xenstat.h
tools/xenstat/xentop/xentop.c

index e0f9de7c0731b56babb977e86d92013f01e8db4a..8c06449db3e19aef26e51dd2ef1297effb73394c 100644 (file)
@@ -173,9 +173,9 @@ int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info,
        return op.u.getdomaininfolist.num_domains;
 }
 
-/* Returns cpu usage data from dom0 */
-long long xi_get_vcpu_usage(xi_handle *handle, unsigned int domain,
-                            unsigned int vcpu)
+/* Get vcpu info from a domain */
+int xi_get_domain_vcpu_info(xi_handle *handle, unsigned int domain, 
+                            unsigned int vcpu, dom0_getvcpuinfo_t *info)
 {
        dom0_op_t op;
        op.u.getvcpuinfo.domain = domain;
@@ -186,7 +186,9 @@ long long xi_get_vcpu_usage(xi_handle *handle, unsigned int domain,
                return -1;
        }
 
-       return op.u.getvcpuinfo.cpu_time;
+       memcpy(info, &op.u.getvcpuinfo, sizeof(dom0_getvcpuinfo_t));
+
+       return 0;
 }
 
 /* gets xen version information from hypervisor */
index 2cda13583edfae0c2f2b6e4aa3ff361f0113e8fe..c1e74edcd6a5314f8dc8bb874c0353dea64b1f2a 100644 (file)
@@ -41,5 +41,6 @@ int xi_get_physinfo(xi_handle *, dom0_physinfo_t *);
 int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int,
                           unsigned int);
 
-/* Returns cpu usage data from dom0 */
-long long xi_get_vcpu_usage(xi_handle *, unsigned int, unsigned int);
+/* Get vcpu info from a domain */
+int xi_get_domain_vcpu_info(xi_handle *, unsigned int, unsigned int,
+                            dom0_getvcpuinfo_t *);
index d9b18dbcd02dc3acacd599dc982708f10e831c7b..85da72b168a6af0cf51eee967fdc9521a5699f27 100644 (file)
@@ -51,7 +51,7 @@ struct xenstat_domain {
        unsigned int id;
        unsigned int state;
        unsigned long long cpu_ns;
-       unsigned int num_vcpus;
+       unsigned int num_vcpus;         /* No. vcpus configured for domain */
        xenstat_vcpu *vcpus;            /* Array of length num_vcpus */
        unsigned long long cur_mem;     /* Current memory reservation */
        unsigned long long max_mem;     /* Total memory allowed */
@@ -61,6 +61,7 @@ struct xenstat_domain {
 };
 
 struct xenstat_vcpu {
+       unsigned int online;
        unsigned long long ns;
 };
 
@@ -229,7 +230,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
                        domain->id = domaininfo[i].domain;
                        domain->state = domaininfo[i].flags;
                        domain->cpu_ns = domaininfo[i].cpu_time;
-                       domain->num_vcpus = domaininfo[i].nr_online_vcpus;
+                       domain->num_vcpus = (domaininfo[i].max_vcpu_id+1);
                        domain->vcpus = NULL;
                        domain->cur_mem =
                            ((unsigned long long)domaininfo[i].tot_pages)
@@ -344,7 +345,7 @@ unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
        return domain->cpu_ns;
 }
 
-/* Find the number of VCPUs allocated to a domain */
+/* Find the number of VCPUs for a domain */
 unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain)
 {
        return domain->num_vcpus;
@@ -432,22 +433,24 @@ xenstat_network *xenstat_domain_network(xenstat_domain * domain,
 static int xenstat_collect_vcpus(xenstat_node * node)
 {
        unsigned int i, vcpu;
+
        /* Fill in VCPU information */
        for (i = 0; i < node->num_domains; i++) {
                node->domains[i].vcpus = malloc(node->domains[i].num_vcpus
                                                * sizeof(xenstat_vcpu));
                if (node->domains[i].vcpus == NULL)
                        return 0;
-
+       
                for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) {
                        /* FIXME: need to be using a more efficient mechanism*/
-                       long long vcpu_time;
-                       vcpu_time = xi_get_vcpu_usage(node->handle->xihandle,
-                                                     node->domains[i].id,
-                                                     vcpu);
-                       if (vcpu_time < 0)
+                       dom0_getvcpuinfo_t info;
+
+                       if (xi_get_domain_vcpu_info(node->handle->xihandle,
+                           node->domains[i].id, vcpu, &info) != 0)
                                return 0;
-                       node->domains[i].vcpus[vcpu].ns = vcpu_time;
+
+                       node->domains[i].vcpus[vcpu].online = info.online;
+                       node->domains[i].vcpus[vcpu].ns = info.cpu_time;
                }
        }
        return 1;
@@ -466,6 +469,12 @@ static void xenstat_uninit_vcpus(xenstat_handle * handle)
 {
 }
 
+/* Get VCPU online status */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu)
+{
+       return vcpu->online;
+}
+
 /* Get VCPU usage */
 unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu)
 {
index c9bbf61958cec67017ac8aae5b53cfe957b802ae..286fa035bf4afd3f522baf5e1f728ec3e1262879 100644 (file)
@@ -119,6 +119,7 @@ xenstat_network *xenstat_domain_network(xenstat_domain * domain,
  */
 
 /* Get VCPU usage */
+unsigned int xenstat_vcpu_online(xenstat_vcpu * vcpu);
 unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu);
 
 
index 386e9326e93f98ac30bf102a588161274a0163de..1cb5e368292675792c338eb55651288db6859906 100644 (file)
@@ -713,13 +713,16 @@ void do_vcpu(xenstat_domain *domain)
 
        num_vcpus = xenstat_domain_num_vcpus(domain);
 
-       /* for all vcpus dump out values */
+       /* for all online vcpus dump out values */
        for (i=0; i< num_vcpus; i++) {
                vcpu = xenstat_domain_vcpu(domain,i);
 
-               if (i != 0 && (i%5)==0)
-                       print("\n        ");
-               print(" %2u: %10llus", i, xenstat_vcpu_ns(vcpu)/1000000000);
+               if (xenstat_vcpu_online(vcpu) > 0) {
+                       if (i != 0 && (i%5)==0)
+                               print("\n        ");
+                       print(" %2u: %10llus", i, 
+                                       xenstat_vcpu_ns(vcpu)/1000000000);
+               }
        }
        print("\n");
 }